<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <include file="Public:header" />
</head>
<body>
  <include file="Public:body_top" />

  <div class="container-fluid">
    <div class="row">
      <div class="col-sm-3 col-md-2 sidebar hidden-xs">
        <div class="menu">
          <dl>
            <dt><i class="cm-order"></i>商家管理</dt>
            <dd class="active"><a href="{:U('Shops/index')}">商家列表</a></dd>
            <dd><a href="{:U('Shops/create')}">创建商家</a></dd>
          </dl>
        </div>
      </div>
      <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
        <div class="main-hd">
          <h5>商家列表</h5>
        </div>
        <div class="main-bd">
          <form method="post" action="{:U('Shops/index')}" class="form-horizontal form-box clearfix">
            <div class="col-md-3">
              <div class="form-group">
                <label class="col-sm-4 control-label">商家名</label>
                <div class="col-sm-8">
                  <input class="form-control" name="name" type="text" placeholder="输入商家名" value="{$name}">
                </div>
              </div>
            </div>
            <div class="col-md-3">
              <div class="form-group">
                <label class="col-sm-4 control-label">手机号</label>
                <div class="col-sm-8">
                  <input class="form-control" name="phone" type="text" placeholder="输入手机号" value="{$phone}">
                </div>
              </div>
            </div>
            <div class="col-md-3">
              <button type="submit" class="btn btn-primary">查询</button>
            </div>
          </form>
          <ul class="nav nav-tabs">
            <li class="{$status > 0 ? ''  : 'active'}"><a href="{:U('Shops/index')}">全部商家</a></li>
            <li class="{$status == 1 ? 'active'  : ''}"><a href="{:U('Shops/index?status=1')}">开启</a></li>
            <li class="{$status == 2 ? 'active'  : ''}"><a href="{:U('Shops/index?status=2')}">关闭</a></li>
          </ul>
          <div class="tab-content">
            <div class="tab-pane active" id="all-order">
              <div class="table-responsive">
                <table class="table table-cmcm">
                  <tr>
                    <th>ID</th>
                    <th>LOGO</th>
                    <th>小程序码</th>
                    <th>名称</th>
                    <th>电话</th>
                    <th>地址</th>
                    <th>备注</th>
                    <th>状态</th>
                    <th>创建时间</th>
                    <th>操作</th>
                  </tr>

                  <volist name="page_list.list" id="vo">
                    <tr>
                      <td>{$vo.id}</td>
                      <td>
                        <notempty name="vo.logo"><a title="查看logo" href="{$vo.logo}" target="_blank">
                      <img src="{$vo.logo}" style="width:40px; height:40px;"></a></notempty>
                      </td>
                      <td>
                        <notempty name="vo.qrcode"><a title="查看店铺二维码" href="{$vo.qrcode}" target="_blank">
                      <img src="{$vo.qrcode}" style="width:40px; height:40px;"></a></notempty>
                      </td>
                      <td width="100">{$vo.name}</td>
                      <td>{$vo.phone}</td>
                      <td>
                        <a href="javascript:void(0)" title="{$vo.addr}">{$vo.alias_addr}</a>
                      </td>
                      <td width="80">
                        <a href="javascript:void(0)" title="{$vo.memo}">{$vo.alias_memo}</a>
                      </td>
                      <td class="index_status">{$vo.status_str}</td>
                      <td>{$vo.created_at}</td>
                      <td>
                        <if condition="$vo.status eq 1">
                          <a title="关闭" href='{:U("Shops/status", "id=$vo[id]&status=2")}'>关闭</a>
                          <else/>
                          <a title="开启" href='{:U("Shops/status", "id=$vo[id]&status=1")}'>开启</a>
                        </if>
                        |
                        <if condition="$vo.status eq 1 ">
                          <a href='{:U("Adverts/add", "shop_id=$vo[id]")}'>广告</a> |
                        </if>
                        <a title="店铺码" href='{:U("Shops/update_wxacode", "id=$vo[id]")}'>店铺码</a> |
                        <a title="编辑" href="{:U('Shops/edit?id=')}{$vo.id}">编辑</a>
                        <if condition="$vo.status eq 2"> |
                          <a title="审核" data-target="#auth-shop" data-toggle="modal" onclick="add_shop_id(this, {$vo.id})">发送审核</a>
                        </if>
                        <if condition="$vo.phone neq ''">
                          | <a title="解绑" href='{:U("Shops/free", "id=$vo[id]")}'>解绑</a>
                        </if>
                      </td>
                    </tr>
                  </volist>
                </table>
              </div>

              <ul class="pagination pull-right">
                <li>
                  <a href="{$page_list.page.first.href}" aria-label="Previous">
                      <span aria-hidden="true">&laquo;</span>
                    </a>
                </li>
                <li>
                  <a href="{$page_list.page.front.href}" aria-label="Previous">
                      <span aria-hidden="true">&lt;</span>
                    </a>
                </li>
                <volist name="page_list.page.list" id="plist">
                  <li <eq name="plist.index" value="1">class="active"</eq>><a href="{$plist.href}">{$plist.page}</a></li>
                </volist>

                <li>
                  <a href="{$page_list.page.after.href}" aria-label="Next">
                      <span aria-hidden="true">&gt;</span>
                    </a>
                </li>
                <li>
                  <a href="{$page_list.page.last.href}" aria-label="Next">
                      <span aria-hidden="true">&raquo;</span>
                    </a>
                </li>
              </ul>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>

  <div class="modal fade" id="auth-shop">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
          <h4 class="modal-title">审核店铺</h4>
        </div>
        <div class="modal-body">
          <div class="shop-item">
            <p>审核结果
              <input type="radio" value="1" name="status" checked> 通过
              <input type="radio" value="2" name="status"> 未通过
            </p>
            <textarea placeholder="备注" rows="3" cols="70" id="audit-content">请点击消息卡片进入小程序，使用申请手机号在我是商户登录，如有疑问请点击小程序联系我们！</textarea>
            <p><button class="btn btn-primary" id="submit-auth" data-shop-id="" onclick="send_template_msg()">提交</button></p>
          </div>
        </div>
      </div>
    </div>
  </div>
  <script type="text/javascript">
    function add_shop_id(obj, id) {
      $('#submit-auth').data('shop-id', id);
    }

    $(function() {
      $('#submit-auth').click(function() {
        var url = "{:U('Shops/send_template_msg')}";
        var shop_id = $('#submit-auth').data('shop-id');
        var status = $('input[name=status]:checked').val();
        var audit_content = $('#audit-content').val();

        $.post(url, {
          id: shop_id,
          status: status,
          audit_content: audit_content
        }, function(data) {
          alert(data.msg);
          $('.modal').modal('hide');
            location.reload();            
        });
      });
    });
  </script>
</body>

</html>